package com.matt.controller.pad.care;

import com.matt.commons.dto.sso.StaffDTO;
import com.matt.commons.model.StatusResponse;
import com.matt.commons.page.PagerQuery;
import com.matt.domain.care.HLHandoverRecord;
import com.matt.service.care.HLHandoverRecordService;
import com.matt.service.care.po.HLHandoverRecordPO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

import static com.matt.foundation.constant.RequestConstant.TICKET;

@RestController
@RequestMapping("/pad/record/handover")
@Slf4j
@Api(tags = "护理记录 - 药品交接")
public class PadCareHandoverController extends CareBaseController<HLHandoverRecord, HLHandoverRecordService, HLHandoverRecordPO> {

    @Autowired
    public void setBaseService(HLHandoverRecordService service){
        super.setBaseService(service);
    }

    @Autowired
    HLHandoverRecordService hlHandoverRecordService;

    @ApiOperation(value = "增加一条记录（使用childId）或多个记录（使用childIds）, 响应结果都是数组")
    @PostMapping(produces = "application/json;charset=UTF-8")
    public StatusResponse add(@RequestHeader(TICKET) String ticket, @RequestBody HLHandoverRecordPO param){
        return super.add(ticket, param );
    }

    @ApiOperation(value = "获取列表")
    @GetMapping("/v2_list")
    public StatusResponse getList(@RequestHeader(TICKET)String ticket, String childId, Date daily, PagerQuery pagerQuery) {
        StaffDTO staff = cache.getStaff(ticket);
        PageRequest pageRequest = PageRequest.of(pagerQuery.getPageNum(), pagerQuery.getPageSize());
        Page<HLHandoverRecord> list = hlHandoverRecordService.getList(staff.getAreaId(), staff.getId(),childId,daily, pageRequest);
        return StatusResponse.success(list);
    }
}
